﻿#include "global.h"


QString Global::soundSelect = "";
QMediaPlayer* Global::player = nullptr;
QString Global::currMusic = "";
int Global::currVoice = 40;

void Global::playSoundEffect(QString soundType, int times, float voice) {
    if(Global::soundSelect.length()) {

        QSoundEffect *effect = new QSoundEffect();
        effect->setSource(QUrl::fromLocalFile(Global::soundSelect + soundType));
        effect->setLoopCount(times);  //循环次数
        effect->setVolume(voice); //音量  0~1之间
        effect->play();

    }
}

void Global::playSoundEffect(QString soundType) {
    playSoundEffect(soundType, 1, 0.4f);
}

const QString Global::getPcName() {
    return QHostInfo::localHostName();
}

const QString Global::getLocal_IP() {
    QString ip = "";
    QList<QNetworkInterface> interFaceList = QNetworkInterface::allInterfaces();
    for(int i = 0; i < interFaceList.size(); ++ i) {
        auto interface = interFaceList.at(i);
        if(interface.flags().testFlag(QNetworkInterface::IsRunning)) {
            QList<QNetworkAddressEntry> entryList = interface.addressEntries();
            foreach (auto entry, entryList) {
                if(QAbstractSocket::IPv4Protocol == entry.ip().protocol() &&
                        entry.ip() != QHostAddress::LocalHost) {
                    ip = entry.ip().toString();
                    break;
                }
            }
        }
    }
    return ip;
}

const QString Global::getAccountName() {
    QDir dir;
    QString accountName = dir.home().dirName();
    return accountName;
}

